package day1129_1;

import java.sql.*;

public class C1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        Class.forName("com.mysql.cj.jdbc.Driver");//1.加载驱动
        Connection  conn= DriverManager.getConnection("jdbc:mysql://localhost:3306/big1?serverTimezone=GMT%2B8&useSSL=false",
                "root","root");//2.
        PreparedStatement  stmt=//3.
                conn.prepareStatement(
                        "select * from stu where id=?");
        stmt.setInt(1,2);
        ResultSet rs=stmt.executeQuery();//4.执行execute更新update语句
        //rs.next()判断结果集合ResultSet rs是否有数据
        while(rs.next()){
            int id=rs.getInt("id");
            String name=rs.getString(2);
            System.out.println(id+":"+name);
        }
        conn.close();//5.关闭数据库连接
    }
}

















